﻿/* Author : Geeta (A0091320W)*/
/* Dated: 27 January 2012, SA-34*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BAL.Controller;
using EntityObjects;
using System.Drawing;

namespace PresentationLayer.View.DepartmentEmployee
{
    public partial class EmpViewReqHisDetails : System.Web.UI.Page
    {
        ViewRequisitionHistoryControl control = new ViewRequisitionHistoryControl();
        public static int flag = 0;
        Employee emp;
        protected void Page_Load(object sender, EventArgs e)
        {
            emp = (Employee)Session["CurrentUser"];
            if (!IsPostBack)
            {
                //for Back button
                if (Request.QueryString["status"] != null && !(Request.QueryString["status"].Equals("")))
                {
                    
                    //status previous one
                    List<String> status_list = control.getStatus();
                    if (status_list != null)
                    {
                        ddRequisition.DataSource = status_list;
                        ddRequisition.DataBind();
                    }

                }
                else
                {
                    List<String> status_list = control.getStatus();
                    if (status_list != null)
                    {
                        ddRequisition.DataSource = status_list;
                        ddRequisition.DataBind();
                    }
                }

            }

    
        }

        protected void ddRequisition_SelectedIndexChanged(object sender, EventArgs e)
        {
            flag = 0;
            lblFromDate.Text = "";
            lblToDate.Text = "";
        }

        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
            lblFromDate.Text = (Calendar1.SelectedDate.Year.ToString() + "-" + Calendar1.SelectedDate.Month.ToString() + "-" + Calendar1.SelectedDate.Day.ToString());
            Calendar1.Visible = false;
        }


        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Calendar1.Visible = true;

        }

        protected void ImgbtnTo_Click(object sender, ImageClickEventArgs e)
        {
            Calendar2.Visible = true;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //flag = 1;
            if (lblFromDate.Text != "" && lblToDate.Text != "")
            {
                DateTime dt1 = DateTime.Parse(lblFromDate.Text);
                DateTime dt2 = DateTime.Parse(lblToDate.Text);

                if (DateTime.Compare(dt2, dt1) < 0)
                {
                    flag = 3;
                    Label4.Visible = true;
                    Label4.Text = "ToDate cannot be earlier than FromDate";
                    RegDetails.DataSource = null;
                    RegDetails.DataBind();
                }
                else
                {
                    Label4.Visible = false;
                }
                
            }
            else
            {
                Label4.Visible = false;

            }


            List<Requisition> req_list = control.getRequisitions(ddRequisition.SelectedValue.ToString(), lblFromDate.Text.ToString(), lblToDate.Text.ToString(), emp.EmpId);

            if (req_list != null)
            {

                RegDetails.DataSource = req_list;
                RegDetails.DataBind();
            }
            else
            {
                RegDetails.DataSource = null;
                RegDetails.DataBind();
            }

            ViewState["ListInViewState"] = req_list;

        }


        protected void RegDetails_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void RegDetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            RegDetails.PageIndex = e.NewPageIndex;
            RegDetails.DataSource = ViewState["ListInViewState"];
            RegDetails.DataBind();
        }

        protected void RegDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow row = RegDetails.Rows[e.RowIndex];
            Control region1 = row.Cells[4].FindControl("ViewDetail");
        }

        protected void reqDetails_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (String.Equals(e.CommandName, "ViewDetail"))
            {
                int rowIndex = Convert.ToInt16(e.CommandArgument);
                String reqFormId = RegDetails.DataKeys[rowIndex].Value.ToString();
                Label3.Text = reqFormId.ToString();
                Server.Transfer("EmpReqHisDetails.aspx?reqFormId=" + reqFormId);
            }
        }

        protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
        {
            if (e.Day.Date > System.DateTime.Today)
            {
                // Disable date
                e.Day.IsSelectable = false;
                // Change color of disabled date
                e.Cell.ForeColor = Color.Gray;
            }

        }

        protected void Calendar2_DayRender(object sender, DayRenderEventArgs e)
        {
            if (e.Day.Date > System.DateTime.Today)
            {
                // Disable date
                e.Day.IsSelectable = false;
                // Change color of disabled date
                e.Cell.ForeColor = Color.Gray;
            }
        }

        protected void Calendar2_SelectionChanged1(object sender, EventArgs e)
        {
            lblToDate.Text = (Calendar2.SelectedDate.Year.ToString() + "-" + Calendar2.SelectedDate.Month.ToString() + "-" + Calendar2.SelectedDate.Day.ToString());
            Calendar2.Visible = false;
            // Panel3.Visible = false;
        }

        protected void Button2_Click(object sender, EventArgs e)
        {

        }

        protected void Calendar2_DayRender1(object sender, DayRenderEventArgs e)
        {
            if (e.Day.Date > System.DateTime.Today)
            {
                // Disable date
                e.Day.IsSelectable = false;
                // Change color of disabled date
                e.Cell.ForeColor = Color.Gray;
            }
        }
    }

}

